package com.itheima.demo2p;

import java.util.Scanner;

public class CarTest {
    public static void main(String[] args) {
        //创建一个数组用来存3个汽车对象
        Car[] arr=new Car[3];

        //2.创建汽车对象,数据来自于键盘录入
        Scanner sc = new Scanner(System.in);

        for (int i = 0; i < arr.length; i++) {
            Car c = new Car();

            //录取品牌
            System.out.println("请输入汽车品牌:");
            String brand = sc.next();
            c.setBrand(brand);

            //录取价格
            System.out.println("请输入汽车价格:");
            int price = sc.nextInt();
            c.setPrice(price);

            //录取颜色
            System.out.println("请输入汽车颜色:");
            String color = sc.next();
            c.setColor(color);

            //把汽车对象添加到数组中
            arr[i]=c;
        }

        //遍历数组
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i].getBrand() + " " + arr[i].getColor() + " " + arr[i].getPrice());
        }

    }


}
